package com.lf.web.service.system.webnode;

import com.lf.data.ClusterUtil;
import com.lf.data.Validate;
import com.lf.data.file.Limit;
import com.lf.web.service.ServiceSupport;
import org.apache.log4j.Logger;

import java.util.Map;

public class WebNodeDetailService extends ServiceSupport {

    private static final Logger log = Logger.getLogger(WebNodeDetailService.class);
    private WebNodeDAO webNodeDAO;
    private Map<String, Object> channel = null;

    public void setWebNodeDAO(WebNodeDAO webNodeDAO) {
        this.webNodeDAO = webNodeDAO;
    }

    public String execute() {
        String id = form.getString("id");
        log.debug("id=" + id);
        if (Validate.check(Validate.OBJECTID, id)) {
            channel = webNodeDAO.findById(id);
            if (channel.isEmpty()) {
                log.error("所查看的频道不存在");
                error(404);
                return NONE;
            }
            Limit limit = new Limit();
            if (limit.load()) {
                context.put("limitConfig", limit.getLimit());
            }
            putData();
            return "detail";
        } else {
            error(404);
            log.error("错误参数：id=" + id);
            return NONE;
        }
    }

    private void putData() {
        context.put("webnode", channel);
        context.put("check", ClusterUtil.getCheck(WebNode.class));
    }

}
